package com.hut.blog.service;

import com.hut.blog.mapper.BlogMapper;
import com.hut.blog.mapper.UserMapper;
import com.hut.blog.model.BlogInfo;
import com.hut.blog.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Base64;

@Slf4j
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private BlogMapper blogMapper;

    public UserInfo selectByName(String userName) {
        return userMapper.getUserInfoByUserName(userName);
    }

    public UserInfo selectById(Integer UserId) {
        return userMapper.getUserInfoById(UserId);
    }



    public UserInfo selectByBolgId(Integer blogId) {
        //根据blogId拿到blog信息
        BlogInfo blogInfo = blogMapper.getBlogInfoById(blogId);
        log.info("blogId:{}", blogId);
        if (blogInfo == null && blogInfo.getUserId() <= 0) {
            log.error("博客不存在或者博客作者信息不合法，blogId:{}", blogId);
            return null;
        }
        //再根据blog信息中的作者Id拿到作者信息
        UserInfo userInfo = userMapper.getUserInfoById(blogInfo.getUserId());
        return userInfo;
    }
}
